package io.yuncheng.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.yuncheng.common.validator.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.yuncheng.modules.sys.entity.SubAppAssessmentConfigEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.yuncheng.modules.sys.entity.SubAppAssessmentConfigEntity;
import io.yuncheng.modules.sys.service.SubAppAssessmentConfigService;
import io.yuncheng.common.utils.PageUtils;
import io.yuncheng.common.utils.R;



/**
 * 密评以及风评方案配置表
 *
 * @author Mark
 * @email 15721509625@163.com
 * @date 2020-10-11 16:24:21
 */
@RestController
@Api(tags = "密评管理配置")
@RequestMapping("sys/subappassessmentconfig")
public class SubAppAssessmentConfigController {
    @Autowired
    private SubAppAssessmentConfigService subAppAssessmentConfigService;

    /**
     * 列表
     */
    @PostMapping("/list")
    @ApiOperation("列表")
    @RequiresPermissions("sys:subappassessmentconfig:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = subAppAssessmentConfigService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @PostMapping("/entity-by-level")
    @ApiOperation("列表")
    @RequiresPermissions("sys:subappassessmentconfig:list")
    public R list(Integer level ){
        SubAppAssessmentConfigEntity entity = new SubAppAssessmentConfigEntity();
        entity.setAppLevel(level);
        QueryWrapper<SubAppAssessmentConfigEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(entity);
        SubAppAssessmentConfigEntity page = subAppAssessmentConfigService.getOne(queryWrapper);
        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation("根据id获取")
    @RequiresPermissions("sys:subappassessmentconfig:info")
    public R info(@PathVariable("id") Long id){
        SubAppAssessmentConfigEntity subAppAssessmentConfig = subAppAssessmentConfigService.getById(id);

        return R.ok().put("subAppAssessmentConfig", subAppAssessmentConfig);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存")
    @RequiresPermissions("sys:subappassessmentconfig:save")
    public R save(@RequestBody SubAppAssessmentConfigEntity subAppAssessmentConfig){
        subAppAssessmentConfigService.save(subAppAssessmentConfig);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("更新")
    @RequiresPermissions("sys:subappassessmentconfig:update")
    public R update(@RequestBody SubAppAssessmentConfigEntity subAppAssessmentConfig){
        ValidatorUtils.validateEntity(subAppAssessmentConfig);
        subAppAssessmentConfigService.updateById(subAppAssessmentConfig);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @PostMapping("/delete")
    @RequiresPermissions("sys:subappassessmentconfig:delete")
    public R delete(@RequestBody Long[] ids){
        subAppAssessmentConfigService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
